package com.gsoe.problem.controller.admin;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gsoe.base.model.Result;
import com.gsoe.problem.dto.ProblemDTO;
import com.gsoe.problem.service.ProblemService;
import com.gsoe.problem.vo.UploadProblemVO;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController()
@RequestMapping("/problem/admin")
public class ProblemAdminController {
    @Autowired
    private ProblemService problemService;

    @PostMapping("/addOrUpdateProblem")
    @SaCheckPermission("problem_add_update")
    public Result<String> addOrUpdateProblem(@RequestBody @Valid ProblemDTO problemDTO){
        problemService.addOrUpdateProblem(problemDTO);
        return Result.success("ok");
    }

    @DeleteMapping("/delById/{id}")
    @SaCheckPermission("problem_del")
    public Result<String> delById(@PathVariable Long id){
        problemService.delByid(id);
        return Result.success("ok");
    }

    @GetMapping("/getTypeNumberList")
    public Result<List<Integer>> getTypeNumberList(){
        return Result.success(problemService.getTypeNumberList());
    }

    @PostMapping("/uploadProblem")
    @SaCheckPermission("problem_add_update")
    public Result<UploadProblemVO> loadProblem(@RequestParam("file") MultipartFile file,@RequestParam("repeatSkip") Boolean repeatSkip){
        return Result.success(problemService.uploadProblem(file,repeatSkip));
    }
}
